package org.example.lc;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class p53 {
    /**
     *  num[i]+max()
     *  暴力超时
     */
    public int maxSubArray(int[] nums) {
        int maxSum = nums[0];

        for(int i = 0;i<nums.length;i+=1) {
            int temp = 0;
            for(int j = i;j<nums.length;j+=1) {
//                if(nums[j]+temp<temp) {
//                    break;
//                }
                temp+=nums[j];
                maxSum = Math.max(maxSum,temp);

            }
        }


        return maxSum;
    }
    @Test
    public void t1() {
        assertEquals(6, maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
    }
    @Test
    public void t2() {
        assertEquals(1, maxSubArray(new int[]{1}));
    }
    @Test
    public void t3() {
        assertEquals(1, maxSubArray(new int[]{-2,1}));
    }
}
